#include <iostream>

using std::cout;
using std::endl;

class Base{
public:
	virtual void print() {
		cout << "Base::print()" << endl;
		}
	virtual void display() {
		cout << "Base::display()" << endl;
	}
	virtual void show() {
		cout << "Base::show()" << endl;
	}
private:
	long _base = 10;
};

class Derived
: public Base
{
public:
 	virtual void print() {
		cout << "Derived::print()" << endl;
	}
	virtual void display() {
		cout << "Derived::display()" << endl;
	}
	virtual void show() {
		cout << "Derived::show(), _derived:" << _derived << endl; 
	}
private:
	long _derived = 100;
};

int main()
{
    Derived d;
    cout << "sizeof(Derived):" << sizeof(Derived) << endl;

    long * p1 = (long *)&d;
    cout << "p1[0]:" << p1[0] << endl;//虚函数表的入口地址
    cout << "p1[1]:" << p1[1] << endl;
    cout << "p1[2]:" << p1[2] << endl;

    long * pvtable = (long*)p1[0];
    cout << "pvtable[0]:" << pvtable[0] << endl;//虚函数的入口地址
    cout << "pvtable[1]:" << pvtable[1] << endl;//虚函数的入口地址
    cout << "pvtable[2]:" << pvtable[2] << endl;//虚函数的入口地址

    //对返回值是void,参数是无参形式的函数进行改名操作
    typedef void(*Function)();//固定写法
    //typedef void()   Function;
                                                
    Function f = (Function)pvtable[0];
    f();
    f= (Function)pvtable[1];
    f();
    f=(Function)pvtable[2];
    f();

    return 0;
}

